package com.leil.java8.函数组合;

import java.util.function.Function;

public class FunctionComposition {

    static Function<String, String>
    f1 = s -> {
        System.out.println("f1:" + s);
        return s.replace('A', '_');
    },
    f2 = s -> {
        System.out.println("f2:" + s);
        return s.substring(3);
    },
    f3 = s -> {
        System.out.println("f3:" + s);
        return s.toLowerCase();
    },
    f4 = f1.compose(f2).andThen(f3);


    public static void main(String[] args) {
        String s = f4.apply("GO AFTER ALL AMBULANCES");
        System.out.println("end:" + s);
    }

    // 运行结果
//    f2:GO AFTER ALL AMBULANCES    可以看出先运行f2->f1->f3
//    f1:AFTER ALL AMBULANCES
//    f3:_FTER _LL _MBUL_NCES
//    end:_fter _ll _mbul_nces


}
